package com.braain.level;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Polygon;

// ====================================
// a generic class for all game objects
// ====================================
public abstract class LevelObject {

  private float x;
  private float y;
  private String type;
  private Polygon poly;
  private String lastFacingDirection;
  private final int boundingBoxWidth;
  private final int boundingBoxHeight;
  //public static boolean debugMode = false;

  public LevelObject(
    float x, float y,
    float topLeftX, float topLeftY,
    float topRightX, float topRightY,
    float downRightX, float downRightY,
    float downLeftX, float downLeftY,
    String type) {

    this.x = x;
    this.y = y;
    this.type = type;
    boundingBoxWidth = (int)topRightX;
    boundingBoxHeight = (int)downRightY;

    // ==================================
    // create a polygon around the object
    // ==================================
    poly = new Polygon(new float[]{
      topLeftX, topLeftY,
      topRightX, topRightY,
      downRightX, downRightY,
      downLeftX, downLeftY
    });
  }

  public int getBoundingBoxWidth() {
    return boundingBoxWidth;
  }

  public int getBoundingBoxHeight() {
    return boundingBoxHeight;
  }

  public float getX() {
    return x;
  }

  public float getY() {
    return y;
  }

  public void setX(float x) {
    this.x = x;
  }

  public void setY(float y) {
    this.y = y;
  }
  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public Polygon getPoly() {
    return poly;
  }

  public void setPoly(Polygon poly) {
    this.poly = poly;
  }

  public String getLastFacingDirection() {
    return lastFacingDirection;
  }

  public void setLastFacingDirection(String lastFacingDirection) {
    this.lastFacingDirection = lastFacingDirection;
  }
  public abstract void update(int delta) throws SlickException;

  public abstract void draw(Graphics g);

  public boolean isCollisionWith(LevelObject other) throws SlickException {
    return poly.intersects(other.poly);
  }
}
